package com.leyou.page.web;

import com.leyou.page.service.GoodsPageService;
import com.leyou.page.vo.SkuVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

//监听canal变化
//这里我们收到消息立马更新redis中的数据
//注意，这里面没有写的方法（注释掉的方法是去更新redis缓存的）
@CanalTable(value = "tb_sku")
@Component
public class SkuHandler implements EntryHandler<SkuVO> {

    @Autowired
    private GoodsPageService pageService;

    //重写里面的增删改方法，当里面skuvo里面发生任意方法都会来这里通知我们
    @Override
    public void insert(SkuVO skuDTO) {
        //pageService.loadSkuListData(skuDTO.getSpuId());
        System.out.println("canal新增------------->skuDTO = " + skuDTO);
    }

    @Override
    public void update(SkuVO before, SkuVO after) {
        //pageService.loadSkuListData(after.getSpuId());
        System.out.println("canal修改------------->skuDTO = " + before);
        System.out.println("canal修改------------->skuDTO = " + after);
    }

    @Override
    public void delete(SkuVO skuDTO) {
        //pageService.deleteSku(skuDTO.getSpuId());
        System.out.println("canal删除------------->skuDTO = " + skuDTO);
    }
}